package com.wlcorp.forcazamis.dao.baseinfo.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.ibatis.dao.client.DaoException;
import com.wlcorp.forcazamis.dao.baseinfo.IFeatureDAO;
import com.wlcorp.forcazamis.domain.baseinfo.Feature;

public class FeatureDAOImpl extends HibernateDaoSupport implements
		IFeatureDAO {

	@SuppressWarnings("unchecked")
	public List getFeatureList(Feature feature) throws DaoException {
		StringBuffer sqlString = new StringBuffer("from Feature as feature where 1=1 and feature.deleteFlag=false");
		if(null != feature && null != feature.getFeatureCode()){
			sqlString.append(" and feature.featureCode = '").append(feature.getFeatureCode())
				.append("'");
		}
		return getHibernateTemplate().find(sqlString.toString());
	}

	public Feature getFeatureById(Long featureId) throws DaoException {
		return (Feature)getHibernateTemplate().get(Feature.class,featureId);
	}

	public void deleteFeature(Feature feature) throws DaoException {
		feature.setDeleteFlag(true);
		getHibernateTemplate().update(feature);
	}

	public void saveFeature(Feature feature) throws DaoException {
		getHibernateTemplate().saveOrUpdate(feature);
	}

}
